package org.example.AI;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: 默苍璃
 * @date: 2024-07-18 14:38
 */
// 具体中介者类
public class ChatRoom implements ChatRoomMediator {
    private List<User> users;

    public ChatRoom() {
        this.users = new ArrayList<>();
    }

    @Override
    public void sendMessage(String message, User user) {
        // 中介者收到消息，广播给其他用户
        for (User u : users) {
            if (u != user) {
                u.receive(message);
            }
        }
    }

    @Override
    public void addUser(User user) {
        users.add(user);
    }
}